﻿using System;
using ThoughtWorks.CruiseControl.Core.Tasks.Conditions;
using Rhino.Mocks;
using ThoughtWorks.CruiseControl.Core;
using ThoughtWorks.CruiseControl.Remote;
using NUnit.Framework;

namespace ThoughtWorks.CruiseControl.UnitTests.Core.Tasks.Conditions
{
    [TestFixture]
    public class buildConditionTaskConditionTest : AssertionHelper
    {
        [Test]
        [Description("basic success")]
        [Category("Category")]
        public void buildConditionTaskConditionTest_basic_success([Values(BuildCondition.ForceBuild, BuildCondition.IfModificationExists, BuildCondition.NoBuild)]BuildCondition inputCondition)
        {
            MockRepository mocks = new MockRepository();

            IIntegrationResult integrationResult = mocks.StrictMock <IIntegrationResult>();
            Rhino.Mocks.Expect.Call(integrationResult.BuildCondition).Return(inputCondition).Repeat.Any();
            mocks.ReplayAll();

            BuildConditionTaskCondition condition = new BuildConditionTaskCondition();
            condition.BuildCondition = inputCondition;
            Assert.That(condition.Eval(integrationResult), Is.True);

            mocks.VerifyAll();
        }

        [Test]
        [Description("MissingValue fails")]
        [Category("Parameter validation")]
        [ExpectedException(typeof(ArgumentException))]
        public void buildConditionTaskConditionTest_MissingValue_fails()
        {
            MockRepository mocks = new MockRepository();

            IIntegrationResult integrationResult = mocks.StrictMock<IIntegrationResult>();
            Rhino.Mocks.Expect.Call(integrationResult.BuildCondition).Return(BuildCondition.ForceBuild).Repeat.Any();
            mocks.ReplayAll();

            BuildConditionTaskCondition condition = new BuildConditionTaskCondition();
            Assert.That(condition.Eval(integrationResult), Throws.ArgumentException);

            mocks.VerifyAll();
        }
    }
}
